package com.stock.demo.function.start.presenter;

import android.text.TextUtils;

import com.stock.demo.function.start.view.LoginActivity;
import com.stock.demo.function.start.view.LoginView;
import com.stock.demo.util.CacheUtils;
import com.stock.demo.util.CommonUtils;
import com.stock.demo.util.Constants;

/**
 * Created by XuZhaoyu on 2017/6/25.
 */

public class LoginPresenterImpl implements LoginPresenter {

    private LoginView mLoginView;

    public LoginPresenterImpl(LoginView loginView) {
        mLoginView = loginView;
    }

    @Override
    public void login(String username, String password) {
        if (mLoginView instanceof LoginActivity) {
            if (TextUtils.equals(CacheUtils.get(((LoginActivity) mLoginView)).getAsString(Constants.KEY_USERNAME), username) && TextUtils.equals(CacheUtils.get(((LoginActivity) mLoginView)).getAsString(Constants.KEY_PASSWORD_MD5), CommonUtils.md5(password))) {
                mLoginView.onLogin(true);
            } else {
                mLoginView.onLogin(false);
            }
        }
    }

}
